﻿//扩展tree,使其支持平滑数据格式（SyPro）
var easyuiTreeLoadFilter = function (data, pid) {
    var treeData = [], tmpMap = [];
    for (var i = 0; i < data.length; i++) { tmpMap[data[i]["id"]] = data[i]; }
    for (var i = 0; i < data.length; i++) {
        if (tmpMap[data[i]["pid"]]) {
            if (!tmpMap[data[i]["pid"]]["children"]) {
                tmpMap[data[i]["pid"]]["children"] = [];
            }
            tmpMap[data[i]["pid"]]["children"].push(data[i]);
        } else { treeData.push(data[i]); }
    }
    return treeData;
};
$.fn.combotree.defaults.loadFilter = easyuiTreeLoadFilter;
$.fn.tree.defaults.loadFilter = easyuiTreeLoadFilter;

//扩展treegrid,使其支持平滑数据格式（SyPro）
var easyuiTreeGridLoadFilter = function (data, pid) {
    var opt = $(this).data().treegrid.options;
    var treeData = [], tmpMap = [];
    for (var i = 0; i < data.length; i++) { tmpMap[data[i][opt.idField]] = data[i]; }
    for (var i = 0; i < data.length; i++) {
        if (tmpMap[data[i][opt.parentField]]) {
            if (!tmpMap[data[i][opt.parentField]]["children"]) {
                tmpMap[data[i][opt.parentField]]["children"] = [];
            }
            tmpMap[data[i][opt.parentField]]["children"].push(data[i]);
        } else { treeData.push(data[i]); }
    }
    return treeData;
};
$.fn.treegrid.defaults.loadFilter = easyuiTreeGridLoadFilter;